import { Opt } from '__com/Opt.js'
import dt from '@dt/dt'
import rolesOpt from '@/option/roles.js'

export class listColumn extends Opt {
  constructor(fun) {
    super(fun)
  }
  create() {
    return [
      {
        field: 'workNo',
        title: '人员编号',
        minWidth: 180,
        header: {
          filter: {
            title: '人员编号',
            key: 'workNo',
            placeholder: '请输入人员编号',
            input: {},
            filter: {
              check: (val) => {
                if (val.workNo.length < 4) {
                  dt.ui.Message.warning('请输入至少4位人员编号。')
                }
                return !(val.workNo.length < 4)
              }
            }
          }
        }
      },
      {
        field: 'userName',
        title: '人员姓名',
        minWidth: 180,
        header: {
          filter: {
            title: '人员姓名',
            key: 'userName',
            placeholder: '请输入人员姓名',
            input: {}
          }
        }
      },
      {
        field: 'phone',
        title: '人员手机号',
        minWidth: 180,
        header: {
          filter: {
            title: '人员手机号',
            key: 'phone',
            placeholder: '请输入人员手机号',
            input: {},
            filter: {
              check: (val) => {
                if (val.phone.length < 4) {
                  dt.ui.Message.warning('请输入至少4位人员手机号。')
                }
                return !(val.phone.length < 4)
              }
            }
          }
        }
      },
      {
        field: 'roleNames',
        title: '人员角色',
        minWidth: 180,
        header: {
          filter: rolesOpt.createSysRole({
            key: 'roleIds',
            title: '人员角色',
            multiple: true,
            maxTagCount: 2
          })
        }
      },
      {
        field: 'state',
        title: '人员状态',
        minWidth: 180,
        header: {
          filter: {
            title: '人员状态',
            key: 'state',
            placeholder: '请选择',
            select: {
              options: [
                {
                  value: '启用',
                  key: '1'
                },
                {
                  value: '禁用',
                  key: '0'
                }
              ]
            }
          }
        },
        cell: (info) => {
          return {
            value: (v) => {
              return info.state == 1 ? '启用' : '禁用'
            },
            text: {}
          }
        }
      },
      {
        field: 'operate',
        title: '操作',
        fixed: 'right',
        width: 160,
        cell: (info) => {
          return {
            btn: [
              {
                title: '编辑',
                color: '#3366FF',
                // code: '0402040000',
                click: (row) => {
                  this.onEdit(row)
                }
              },
              {
                title: info.state == 1 ? '禁用' : '启用',
                color: info.state == 1 ? '#F33C3C' : '#19BE6B',
                // code: '0402050000',
                click: (row) => {
                  this.onChangeStatus(row)
                }
              }
            ]
          }
        }
      }
    ]
  }
}
